use strict;
use warnings;
use Test::More tests => 31;
use URI;
use File::Slurp;

use Carp 'confess';
$SIG{__DIE__} = \&confess;

BEGIN { use_ok 'Text::Microformat' }
use Data::Dumper;
$Data::Dumper::Terse = 1;
$Data::Dumper::Useqq = 1;
my $html = read_file('t/mott.xml');
my $uformat = Text::Microformat->new($html, content_type => 'application/rss+xml');
my @things = $uformat->find;
#print STDERR ref $things[0]->grantee->[0]->fn, "\n";
is($things[0]->Get('id'), '200000067.07');
is($things[0]->Get('title'), 'General Purposes');
is($things[0]->GetM('grantee.url'), undef);
is($things[0]->Get('grantee.fn'), 'CIVICUS: World Alliance for Citizen Participation');
is($things[0]->Get('period.dtstart'), '20070330T000000');
is($things[0]->Get('period.dtend'), '20071231T000000');
is($things[0]->Get('description'), 'CIVICUS is an international alliance dedicated to strengthening citizen action and civil society globally. This grant continues general support to enable CIVICUS to enhance its core organizational systems and structures; undertake a comprehensive strategic and operational planning process for 2008-2012; and continue with the implementation of its various programs: Civil Society Index, Civil Society Watch, the CIVICUS World Assembly, Knowledge Development and Dissemination, and Participatory Governance. The grant also will assist CIVICUS with a succession planning process to find a new Secretary General.');
is($things[0]->Get('grantor.url'), 'http://www.mott.org');
is($things[0]->Get('grantor.fn'), 'Charles Stewart Mott Foundation');

$html = read_file('t/mott2.xml');
$uformat = Text::Microformat->new($html, content_type => 'application/rss+xml');
@things = $uformat->find({format => 'hGrant'});
#print STDERR ref $things[0]->grantee->[0]->fn, "\n";

is($things[0]->Get('id'), '198100183');
is($things[0]->Get('title'), 'General Purposes');
is($things[0]->GetM('grantee.url'), 'http://www.IndependentSector.org');
is($things[0]->Get('grantee.fn'), 'Independent Sector');
is($things[0]->Get('grantee.adr.street-address'), '1200 Eighteenth Street, NW, Suite 200');
is($things[0]->Get('period.dtstart'), '20060304T000000');
is($things[0]->Get('period.dtend'), '19821231T000000');
is($things[0]->Get('description'), '');
is($things[0]->Get('grantor.url'), 'http://www.mott.org');
is($things[0]->Get('grantor.fn'), 'Charles Stewart Mott Foundation');
is($things[0]->Get('grantor.adr.street-address'), '503 S. Saginaw Street, Suite 1200');
is($things[0]->Get('grantor.adr.locality'), 'Flint');
is($things[0]->Get('grantor.adr.region'), 'Michigan');
is($things[0]->Get('grantor.adr.postal-code'), '48502-1851');
is($things[0]->Get('geo-focus.locality'), 'Flint');
is($things[0]->Get('geo-focus.region'), 'MI');
is($things[0]->GetH('geo-focus.region'), 'Michigan');
is($things[0]->Get('geo-focus.postal-code'), '12345');

is($things[0]->program_focus->[0]->tags->[0]->HumanValue, 'Environment');
is($things[0]->program_focus->[0]->tags->[1]->HumanValue, 'Solar Power');
is($things[0]->program_focus->[0]->tags->[2]->HumanValue, 'Technology');
